package com.usian.admin.controller;

import com.usian.admin.service.AdSensitiveService;
import com.usian.apis.admin.admin.SensitiveControllerApi;
import com.usian.model.admin.dtos.SensitiveDto;
import com.usian.model.admin.pojos.AdSensitive;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.utils.common.BCrypt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/sensitive")
public class AdSensitiveController implements SensitiveControllerApi {

    @Autowired
    private AdSensitiveService adSensitiveService;

    @PostMapping("/list")
    @Override
    public ResponseResult list(@RequestBody SensitiveDto dto) {
        return adSensitiveService.list(dto);
    }

    @PostMapping("/save")
    @Override
    public ResponseResult save(@RequestBody AdSensitive adSensitive) {
        return adSensitiveService.insert(adSensitive);
    }

    @PostMapping("/update")
    @Override
    public ResponseResult update(@RequestBody AdSensitive adSensitive) {
        return adSensitiveService.update(adSensitive);
    }

    @DeleteMapping("/del/{id}")
    @Override
    public ResponseResult deleteById(@PathVariable("id") Integer id) {
        return adSensitiveService.deleteById(id);
    }

    public static void main(String[] args) {
//        //md5加密  DegestUtils：spring框架提供的工具类
//        String md5Str = DigestUtils.md5DigestAsHex("abc".getBytes());
//        System.out.println(md5Str);//900150983cd24fb0d6963f7d28e17f72

//        String gensalt = BCrypt.gensalt();//这个是盐  29个字符，随机生成
//        System.out.println(gensalt);
//        String password = BCrypt.hashpw("123456", gensalt);  //根据盐对密码进行加密
//        System.out.println(password);//加密后的字符串前29位就是盐

        boolean checkpw = BCrypt.checkpw("123456","$2a$10$coTW/wOq7hcj5Mii9y.NwO9OEaD40Ajqn6ZwgkFMz9D8PdbuMZRC2");
        System.out.println(checkpw);
    }
}